﻿using MvcApplication.Common;
using MvcApplication.Entity;
using MvcApplication.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication.Controllers
{
    public class InstallerController : Controller
    {
        IInstallerService _installerService;

        public InstallerController(IInstallerService installerService)
        {
            _installerService = installerService;
        }

        public ActionResult Index()
        {
            try
            {
                var hasInit = _installerService.HasMember();
                if (hasInit) throw new BizException("系统已经初始化，不能通过安装页面进行安装。。。");
                return View();
            }
            catch (BizException bzE)
            {
                throw bzE;
            }
            catch
            {
                return View();
            }

        }

        public JsonResult Install(InstallInfoDto info, UserInfo user)
        {
            _installerService.Install(info, user);

            return Json(true);
        }
    }
}
